package com.abaaba.project2.service.serviceImpl;

import com.abaaba.project2.bean.System;
import com.abaaba.project2.bean.bo.MallConfigBO;
import com.abaaba.project2.bean.vo.AdminConfigVO;
import com.abaaba.project2.mapper.SystemMapper;
import com.abaaba.project2.service.AdminConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author Hedgehog
 * @Date 2021/6/5 23:51
 * @Version 1.0
 */
@Service
public class AdminConfigServiceImpl implements AdminConfigService {

    @Autowired
    SystemMapper systemMapper;

    @Override
    public AdminConfigVO selectMall() {
        //获取四个pojo
        System systemName = systemMapper.selectByPrimaryKey(38);
        System systemQq = systemMapper.selectByPrimaryKey(40);
        System systemPhone = systemMapper.selectByPrimaryKey(44);
        System systemAddress = systemMapper.selectByPrimaryKey(46);
        //获取值
        String name = systemName.getKeyValue();
        String qq = systemQq.getKeyValue();
        String phone = systemPhone.getKeyValue();
        String address = systemAddress.getKeyValue();
        //封装
        AdminConfigVO adminConfigVO = new AdminConfigVO();
        adminConfigVO.setCskaoyanmall_mall_qq(qq);
        adminConfigVO.setCskaoyanmall_mall_name(name);
        adminConfigVO.setCskaoyanmall_mall_phone(phone);
        adminConfigVO.setCskaoyanmall_mall_address(address);
        return adminConfigVO;
    }

    @Override
    public void updateMall(MallConfigBO mallConfigBO) {
        System systemName = new System();
        systemName.setId(38);
        systemName.setKeyValue(mallConfigBO.getCskaoyanmall_mall_name());

        System systemQq = new System();
        systemQq.setId(40);
        systemQq.setKeyValue(mallConfigBO.getCskaoyanmall_mall_qq());

        System systemPhone = new System();
        systemPhone.setId(44);
        systemPhone.setKeyValue(mallConfigBO.getCskaoyanmall_mall_phone());

        System systemAddress = new System();
        systemAddress.setId(46);
        systemAddress.setKeyValue(mallConfigBO.getCskaoyanmall_mall_address());

        systemMapper.updateByPrimaryKeySelective(systemName);
        systemMapper.updateByPrimaryKeySelective(systemQq);
        systemMapper.updateByPrimaryKeySelective(systemPhone);
        systemMapper.updateByPrimaryKeySelective(systemAddress);
    }
}
